Applications / Proposal Application / Create Proposal and revisioning
New Proposals
-
DB
-
BOQ (Quantity entry screen)
UI
0){ foreach($categories as $cIndex=>$cat){ ?>
Add Line Category{{$cIndex+1}} x
SI Item Quantity Unit {{$cIndex+1}}.{{$iIndex+1}} x Xw1.1 x Xw1 x
SI Item Quantity Unit 1.1 x XScript
var cat_count='0'; var item_count=0; var PRODUCT_SEARCH=""; $('body').on("keyup", ".autocomplete" , function() { var length=$(this).val().length; target=$(this); $(this).parent().parent().find('.clear_product').hide(); if(length>0){ $(this).parent().parent().find('.clear_product').show(); } else{ target.parent().parent().find('.sku_id').val(''); target.parent().parent().find('.item_description').val(''); target.parent().parent().find('.item_quantity').val(''); target.parent().parent().find('.item_unit').val(''); target.parent().parent().find('.item_total').val(0); updateGrandTotal(); } }); $('body').on('focus', '.autocomplete', function (e) { target=$(this); $(this).autocomplete({ source: function( request, response ) { $.ajax({ url: PRODUCT_SEARCH, type: 'get', dataType: "json", data: { search: request.term }, headers: { }, success: function( data ) { numItems=Object.keys(data).length; switch(numItems){ case 0: target.val(''); target.parent().parent().find('.sku_id').val(''); target.parent().parent().find('.item_description').val(''); target.parent().parent().find('.item_quantity').val(''); target.parent().parent().find('.item_unit').val(''); target.parent().parent().find('.item_total').val(0); updateGrandTotal(); target.focus(); break; case 1: // target.val(data[0].label); target.parent().parent().find('.sku_id').val(data[0].sku_id); target.parent().parent().find('.item_description').val(data[0].description); target.parent().parent().find('.item_unit').val(data[0].unit); target.parent().parent().find('.item_quantity').val(''); // target.parent().parent().find('.item_quantity').focus(); break; default: response( data ); break; } } }); }, select: function (event, ui) { target.val(ui.item.label); // display the selected text target.parent().parent().find('.sku_id').val(ui.item.sku_id); target.parent().parent().find('.item_description').val(ui.item.description); target.parent().parent().find('.item_unit').val(ui.item.unit); target.parent().parent().find('.item_quantity').val(''); // target.parent().parent().find('.item_quantity').focus(); var keyCode = event.keyCode || event.which; if (keyCode == 9) { event.preventDefault(); // stops its action } return false; }, focus: function(event, ui){}, open: function() {}, close: function(event, ui) { }, }); }); $('body').on("click", ".clear_product" , function() { $(this).parent().parent().find('.autocomplete').val(''); target=$(this); target.parent().parent().parent().find('.sku_id').val(''); target.parent().parent().parent().find('.item_description').val(''); target.parent().parent().parent().find('.item_quantity').val(''); target.parent().parent().parent().find('.item_unit').val(''); target.parent().parent().parent().find('.item_total').val(0); $(this).hide(); }); $('body').on("click", ".btn_delete" , function() { $(this).parent().parent().remove(); }); $('body').on("click", ".btn_new_category" , function() { //cat_count++; cat_count=$('#boq_container > tbody > tr').length; item_count=0; var str=''; str+=' '; str+=' '; $('#boq_container').append(str); }); $('body').on("click", ".btn_new_items" , function() { var i_cat_count=$(this).attr('data-cat_count'); var i_item_count=$(this).attr('data-item_count'); var i_item_count=$(this).parent().find('.item_container > tbody > tr').length-1; //alert(i_item_count); //i_item_count++; $(this).attr('data-item_count', i_item_count); var str=''+cat_count+' '; str+='x '; str+=''; str+=''; str+=' '; str+='
'; str+=''; str+='
'; str+=' Add Line Items'; str+=''; str+=' '; str+='SI '; str+='x '; str+='Item '; str+='Quantity '; str+='Unit '; str+=''; str+=' '; str+=''+cat_count+'.1 '; str+=''; str+=' '; str+=' '; str+='X'; str+=' '; str+=''; str+=''; str+=' '; str+='w'; str+=' '; str+=' '; $(this).prev('.item_container').append(str); }); /* for items */ $('body').on("click", ".btn_add_items" , function() { error=0; var i_item_count=$(this).parent().find('.item_container > tbody > tr').length; //alert(i_item_count); var date=$(this).parent().parent().find('.date').val(); var description=$(this).parent().parent().find('.description').val(); var category_id=$(this).parent().parent().find('.category_id').val(); var amount=$(this).parent().parent().find('.amount').val(); if(date=='' || description=='' || category_id=='' || amount==''){ error=1; Swal.fire({ icon: 'warning', title: "Please enter mandatory data.", }); } if(error==0){ //$(this).hide(); $(this).parent().find('.btn_delete').show(); var str=''; str+=''+(parseInt(i_cat_count)+1)+'.'+(parseInt(i_item_count)+1)+' '; str+='x '; str+=''; str+=' '; str+='X'; str+=' '; str+='w'; str+=''; str+=' '; str+='w'; str+=' '; str+=' '; //$(this).parent().parent().parent().parent('.item_container').append(str); $(this).prev('.item_container').append(str); //$('.item_container').append(str); //$('.autocomplete').focus(); } return false; });x '; str+=''; str+=' '; str+=' '; //str+=''; str+=''; str+=''; str+=''; str+=''; str+='+x '; str+='in controller
$leadBoq=LeadBoq::where('lead_id',$input['lead_id'])->first(); if(isset($leadBoq)){ $leadBoq->comment=$input['comment']; $leadBoq->save(); $leadBoqId=$leadBoq->id; $message="Successfully updated"; } else{ $leadBoq=LeadBoq::create([ 'lead_id'=>$input['lead_id'], 'created_by' =>$user->master_id, 'comment' =>$input['comment'] ]); $leadBoqId=$leadBoq->id; } if(isset($input['categories'])){ foreach($input['categories'] as $key=>$val){ if(isset($val['category_id']) && $val['category_id']>0){ $val['company_id']=$user->company_id; $val['lead_id']=$input['lead_id']; $val['boq_id']=$leadBoqId; if(isset($val['boq_category_id'])){ $val['id']=$val['boq_category_id']; } $categories=LeadBoqCategory::create($val); //echo count($val['items']); if(isset($val['items'])){ foreach($val['items'] as $key1=>$val1){ if(isset($val1['sku_id']) && $val1['sku_id']>0){ if(isset($val1['boq_item_id'])){ $val1['id']=$val1['boq_item_id']; } $val1['boq_id']=$leadBoqId; $val1['category_id']=$categories->id; $items=LeadBoqItem::create($val1); } //print_r($items); // echo '
'; } } } } }Search function
public function item_search(Request $request){ $input=$request->all(); $parts=Item::select('id as item_id','item_name as label' ) ->where('status','1') ->where('item_name','LIKE',"%{$input['search']}%") ->get(); return response()->json( $parts , 200); } DB
CREATE TABLE `lead_boqs` ( `id` bigint(20) UNSIGNED NOT NULL, `lead_id` bigint(20) DEFAULT NULL, `comment` text DEFAULT NULL, `status` enum('1','0') DEFAULT '1', `created_at` timestamp NULL DEFAULT NULL, `created_by` bigint(20) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE `lead_categories` ( `id` bigint(20) UNSIGNED NOT NULL, `parent_id` int(11) DEFAULT NULL, `name` varchar(255) NOT NULL, `status` enum('1','0') DEFAULT '1', ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE `lead_boq_categories` ( `id` bigint(20) UNSIGNED NOT NULL, `boq_id` bigint(20) DEFAULT NULL, `category_id` int(11) DEFAULT NULL, `status` enum('1','0') DEFAULT '1', `created_at` timestamp NULL DEFAULT NULL, `created_by` bigint(20) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE `lead_boq_items` ( `id` bigint(20) UNSIGNED NOT NULL, `boq_category_id` bigint(20) DEFAULT NULL, `sku_id` bigint(20) DEFAULT NULL, `title` varchar(250) DEFAULT NULL, `description` text DEFAULT NULL, `quantity` decimal(20,2) DEFAULT NULL, `unit` varchar(50) DEFAULT NULL, `status` enum('1','0') DEFAULT '1', `created_at` timestamp NULL DEFAULT NULL, `created_by` bigint(20) DEFAULT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -
Proposal
Proposal List
Proposal price entry screen
UI
$cat){ ?>
{{$cIndex+1}}
SI Item Quantity Unit Getting Price Vendor Tax Rate Excl. Tax Margin % Selling Price Excl Tax {{$cIndex+1}}.{{$iIndex+1}} Script
$('body').on("keyup", ".g_price , .margin_rate" , function() { var quantity=$(this).parent().parent().find('.quantity').val(); var margin_rate=$(this).parent().parent().find('.margin_rate').val(); var tax_rate=$(this).parent().parent().find('.tax_rate').val(); var g_price=$(this).parent().parent().find('.g_price').val(); var gp_excluding_tax=0; var gp_including_tax=0; // getting price if(g_price>0){ gp_excluding_tax=parseFloat(quantity)*parseFloat(g_price); gp_including_tax=gp_excluding_tax; } $(this).parent().parent().find('.gp_excluding_tax').val(gp_excluding_tax); // tax calculation let gp_tax_amount=0; if(tax_rate>0){ gp_tax_amount=(gp_excluding_tax)*parseFloat(tax_rate)/100; gp_including_tax=gp_excluding_tax+gp_tax_amount; } $(this).parent().parent().find('.gp_tax_amount').val(gp_tax_amount); $(this).parent().parent().find('.gp_including_tax').val(gp_including_tax); //selling price let s_price=g_price; if(margin_rate>0){ s_price=parseFloat(g_price)+(parseFloat(g_price)*parseFloat(margin_rate)/100); // need to show } $(this).parent().parent().find('.s_price').val(s_price); let sp_including_tax=s_price; let sp_tax_amount=0; let sp_excluding_tax=parseFloat(quantity)*parseFloat(s_price); $(this).parent().parent().find('.sp_excluding_tax').val(sp_excluding_tax); //tax if(tax_rate>0){ sp_tax_amount=(sp_excluding_tax)*parseFloat(tax_rate)/100; sp_including_tax=sp_excluding_tax+sp_tax_amount; } $(this).parent().parent().find('.sp_tax_amount').val(sp_tax_amount); $(this).parent().parent().find('.sp_including_tax').val(sp_including_tax); updateGrandTotal(); }); function updateGrandTotal(){ var sub_total_g=0; var tax_total_g=0; var sub_total_incltax_g=0; var grand_total_g=0; var sub_total_s=0; var tax_total_s=0; var sub_total_incltax_s=0; var grand_total_s=0; var quantity=$('.quantity'); var gp_excluding_tax=$('.gp_excluding_tax'); var gp_tax_amount=$('.gp_tax_amount'); var gp_including_tax=$('.gp_including_tax'); var s_price=$('.s_price'); var sp_excluding_tax=$('.sp_excluding_tax'); var sp_tax_amount=$('.sp_tax_amount'); var sp_including_tax=$('.sp_including_tax'); $('.g_price').each(function(index, obj){ //alert(quantity[index].value); if(obj.value>0){ //getting if(gp_excluding_tax[index].value>0){ sub_total_g+=parseFloat(gp_excluding_tax[index].value); } if(gp_tax_amount[index].value>0){ tax_total_g+=parseFloat(gp_tax_amount[index].value); } if(gp_including_tax[index].value>0){ sub_total_incltax_g+=parseFloat(gp_including_tax[index].value); } //selling if(sp_excluding_tax[index].value>0){ sub_total_s+=parseFloat(sp_excluding_tax[index].value); } if(sp_tax_amount[index].value>0){ tax_total_s+=parseFloat(sp_tax_amount[index].value); } if(sp_including_tax[index].value>0){ sub_total_incltax_s+=parseFloat(sp_including_tax[index].value); } } }); let round_off_amount_g=Math.round(sub_total_incltax_g); let round_off_diff_g=round_off_amount_g-sub_total_incltax_g; let round_off_amount_s=Math.round(sub_total_incltax_s); let round_off_diff_s=round_off_amount_s-sub_total_incltax_s; $('.sub_total_g').val(sub_total_g.toFixed(2)); $('.tax_total_g').val(tax_total_g.toFixed(2)); $('.round_off_g').val(round_off_diff_g.toFixed(2)); $('.grand_total_g').val(round_off_amount_g.toFixed(2)); $('.sub_total').val(sub_total_s.toFixed(2)); $('.tax_total').val(tax_total_s.toFixed(2)); $('.round_off').val(round_off_diff_s.toFixed(2)); $('.grand_total').val(round_off_amount_s.toFixed(2)); let margin_total=sub_total_s-sub_total_g; $('.margin_total').val(margin_total.toFixed(2)); }
Controller
$fYear=$this->_getFinancialYear(date("Y-m-d"), "Y"); if(isset($input['version_id']) && $input['version_id']>0 && $input['version']!='n' ){ $proposal=LeadProposal::find($input['version_id']); if(isset($proposal) && $proposal->proposal_master_id>0){ $proposal_master_id=$proposal->proposal_master_id; } else{ $proposalMaster=LeadProposalMaster::create([ 'company_id'=>$user->company_id, 'lead_id' =>$input['lead_id'] ]); $proposal_master_id=$proposalMaster->id; } $input['proposal_master_id']=$proposal_master_id; $proposal_id=$input['version_id']; if($input['version']!='r'){ $version=LeadProposal::where('proposal_master_id',$input['proposal_master_id'])->count(); if($version>1){ $version=$fYear.' - Rev-'.($version-1); } else{ $version=$fYear; } $proposal->mode=$input['mode']; $proposal->status=$status; $proposal->sub_total=$input['sub_total']; $proposal->tax_total=$input['tax_total']; $proposal->grand_total=$input['grand_total']; $proposal->round_off=$input['round_off']; $proposal->sub_total_g=$input['sub_total_g']; $proposal->tax_total_g=$input['tax_total_g']; $proposal->grand_total_g=$input['grand_total_g']; $proposal->round_off_g=$input['round_off_g']; $proposal->margin_total=$input['margin_total']; $proposal->version=$version; $proposal->valid_till=$input['valid_till']; $proposal->bank_id=$input['bank_id']; $proposal->save(); } else{ $version=LeadProposal::where('proposal_master_id',$input['proposal_master_id'])->count(); if($version>0){ $version=$fYear.' - Rev-'.($version); } else{ $version=$fYear; } } } else{ $proposalMaster=LeadProposalMaster::create([ 'company_id'=>$user->company_id, 'lead_id' =>$input['lead_id'] ]); $version=$fYear; $proposal_master_id=$proposalMaster->id; } if($input['version']!='u'){ $proposal=LeadProposal::create([ 'lead_id' =>$input['lead_id'], 'proposal_master_id' =>$proposal_master_id, 'company_id' =>$user->company_id, 'status' =>$status, 'mode' =>$input['mode'], 'sub_total'=>$input['sub_total'], 'tax_total'=>$input['tax_total'], 'grand_total'=>$input['grand_total'], 'round_off'=>$input['round_off'], 'sub_total_g'=>$input['sub_total_g'], 'tax_total_g'=>$input['tax_total_g'], 'grand_total_g'=>$input['grand_total_g'], 'round_off_g'=>$input['round_off_g'], 'margin_total'=>$input['margin_total'], 'created_by'=>$user->master_id, 'version' =>$version, 'valid_till'=>isset($input['valid_till']) ? date('Y-m-d') : '', 'bank_id'=>$input['bank_id'] ]); $proposal_id=$proposal->id; } LeadProposalCategory::where('proposal_id',$proposal_id)->delete(); LeadProposalItem::where('proposal_id',$proposal_id)->delete(); if(isset($input['categories'])){ foreach($input['categories'] as $val){ $val['proposal_id']=$proposal_id; $categories=LeadProposalCategory::create($val); if($input['mode']=='confirm'){ $val['proposal_history_id']=$proposalHistory->id; $leadProCatHistory=LeadProposalCatHistory::create($val); } if($val['items']){ foreach($val['items'] as $val1){ $val1['proposal_category_id']=$categories->id; if(isset($val1['g_price']) && $val1['g_price']>0 ){ $items=LeadProposalItem::create($val1); if($input['mode']=='confirm'){ $val1['proposal_category_id']=$leadProCatHistory->id; LeadProposalItemHistory::create($val1); } } } } } } Populate form data
if($view_mode==0){ $this->data['categories']=LeadBoqCategoryRepository::getAll(['lead_id' => $input['lead_id']]); } else{ $this->data['categories']=LeadProposalCategoryRepository::getAll(['lead_id' => $input['lead_id'],'proposal_id' =>$input['id']]); } DB
CREATE TABLE `lead_proposal_masters` ( `id` bigint(20) UNSIGNED NOT NULL, `lead_id` bigint(20) DEFAULT NULL, `status` char(25) DEFAULT '1', `priority` int(11) DEFAULT NULL, `deleted_at` timestamp NULL DEFAULT NULL, `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, `created_by` bigint(20) DEFAULT NULL, `updated_by` bigint(20) DEFAULT NULL, `deleted_by` bigint(20) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE `lead_proposals` ( `id` bigint(20) UNSIGNED NOT NULL, `company_id` int(11) DEFAULT NULL, `lead_id` bigint(20) DEFAULT NULL, `proposal_master_id` bigint(20) DEFAULT NULL, `version` varchar(500) NOT NULL, `status` char(25) DEFAULT '1', `mode` char(25) DEFAULT NULL, `sub_total` decimal(20,2) DEFAULT NULL, `tax_total` decimal(20,2) DEFAULT NULL, `round_off` decimal(20,2) DEFAULT NULL, `grand_total` decimal(20,2) DEFAULT NULL, `sub_total_g` decimal(20,2) DEFAULT NULL, `tax_total_g` decimal(20,2) DEFAULT NULL, `round_off_g` decimal(20,2) DEFAULT NULL, `grand_total_g` decimal(20,2) DEFAULT NULL, `margin_total` decimal(20,2) DEFAULT NULL, `comment` text DEFAULT NULL, `priority` int(11) DEFAULT NULL, `valid_till` date DEFAULT NULL, `bank_id` int(11) DEFAULT NULL, `deleted_at` timestamp NULL DEFAULT NULL, `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, `created_by` bigint(20) DEFAULT NULL, `updated_by` bigint(20) DEFAULT NULL, `deleted_by` bigint(20) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE `lead_proposal_categories` ( `id` bigint(20) UNSIGNED NOT NULL, `proposal_id` bigint(20) DEFAULT NULL, `category_id` int(11) DEFAULT NULL, `status` enum('1','0') DEFAULT '1', `priority` int(11) DEFAULT NULL, `deleted_at` timestamp NULL DEFAULT NULL, `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, `created_by` bigint(20) DEFAULT NULL, `updated_by` bigint(20) DEFAULT NULL, `deleted_by` bigint(20) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE `lead_proposal_items` ( `id` bigint(20) UNSIGNED NOT NULL, `proposal_id` int(11) DEFAULT NULL, `proposal_category_id` bigint(20) DEFAULT NULL, `boq_items_id` int(11) DEFAULT NULL, `sku_id` bigint(20) DEFAULT NULL, `title` varchar(250) DEFAULT NULL, `description` text DEFAULT NULL, `quantity` decimal(20,2) DEFAULT NULL, `unit` varchar(50) DEFAULT NULL, `g_price` decimal(20,2) DEFAULT NULL, `vendor_id` int(11) DEFAULT NULL, `tax_rate` decimal(5,2) DEFAULT NULL, `gp_excluding_tax` decimal(20,2) DEFAULT NULL, `gp_including_tax` decimal(20,2) DEFAULT NULL, `margin_rate` decimal(5,2) DEFAULT NULL, `s_price` decimal(20,2) DEFAULT NULL, `sp_tax_amount` decimal(20,2) DEFAULT NULL, `gp_tax_amount` decimal(20,2) DEFAULT NULL, `sp_excluding_tax` decimal(20,2) DEFAULT NULL, `sp_including_tax` decimal(20,2) DEFAULT NULL, `status` enum('1','0') DEFAULT '1', `priority` int(11) DEFAULT NULL, `deleted_at` timestamp NULL DEFAULT NULL, `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, `created_by` bigint(20) DEFAULT NULL, `updated_by` bigint(20) DEFAULT NULL, `deleted_by` bigint(20) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;